//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __AURA_INTERFACE_H__
#define __AURA_INTERFACE_H__

#include <auratypes.h>

// Interfaces for "System" of Aura.

AURA_API AuraSystem_GetTime(
        /* [out] */ Aura_SystemTime * pTime);

AURA_API AuraSystem_SetTime(
        /* [in] */ Aura_SystemTime * pTime);

AURA_API AuraSystem_QueryPerformanceCounter(
        /* [out] */ Aura_Int64 * pCounter);

AURA_API AuraSystem_QueryPerformanceFrequency(
        /* [out] */ Aura_Int64 * pFrequency);

AURA_API AuraSystem_GetElapsedTime(
        /* [out] */ Aura_Millisecond32 * pTime);

AURA_API AuraSystem_GetIdleTime(
        /* [out] */ Aura_Millisecond32 * pTime);

AURA_API AuraSystem_GetMemorySizes(
        /* [out] */ Aura_Int32 * pTotalPhysicalMemorySize,
        /* [out] */ Aura_Int32 * pAvailablePhysicalMemorySize);

AURA_API AuraSystem_ErrorPrint(
        /* [in] */ Aura_PWChar wstr);

// Interfaces for "Process" of Aura.

AURA_API_(Aura_ProcessId) AuraProcess_GetCurrentId();

AURA_API_(Aura_Void) AuraProcess_Exit(
        /* [in] */ Aura_ExitCode exitCode);  // never returned.

AURA_API AuraProcess_GetStartInfo(
        /* [out] */ Aura_PWChar pImageName,
        /* [out] */ Aura_PWChar pArguments);

AURA_API AuraProcess_GetPriorityRank(
        /* [out] */ Aura_ThreadPriorityRank * pPrirorityRank);

AURA_API AuraProcess_SetPriorityRank(
        /* [in] */ Aura_ThreadPriorityRank priorityRank);

AURA_API AuraProcess_GetProcessorTimes(
        /* [out] */ Aura_Millisecond32 * pUserTime,
        /* [out] */ Aura_Millisecond32 * pPrivilegedTime);

AURA_API AuraProcess_GetMemoryInformation(
        /* [out] */ Aura_Int32 * pPrivateVirtualMemorySize,
        /* [out] */ Aura_Int32 * pSharedVirtualMemorySize,
        /* [out] */ Aura_Int32 * pPrivatePhysicalMemorySize,
        /* [out] */ Aura_Int32 * pSharedPhysicalMemorySize);


// Interfaces for "Thread" of Aura.
typedef Aura_ECode (*PAuraThreadMain)(Aura_PVoid);

AURA_API AuraThread_Create(
        /* [in] */ PAuraThreadMain pEntry,
        /* [in] */ Aura_PVoid pArgument,
        /* [in] */ Aura_ThreadCreationFlags creationFlags,
        /* [out] */ Aura_Handle * phThread,
        /* [out] */ Aura_ThreadId * pThreadId);

AURA_API AuraThread_Resume(
        /* [in] */ Aura_Handle hThread);

AURA_API AuraThread_Suspend(
        /* [in] */ Aura_Handle hThread);

AURA_API AuraThread_Join(
        /* [in] */ Aura_Handle hThread,
        /* [in] */ Aura_Millisecond32 timeOut,
        /* [out] */ Aura_WaitResult * pResult);

AURA_API AuraThread_Abort(
        /* [in] */ Aura_Handle hThread,
        /* [in] */ Aura_QuitCode quitCode);

AURA_API AuraThread_Interrupt(
        /* [in] */ Aura_Handle hThread);

AURA_API AuraThread_Destroy(
        /* [in] */ Aura_Handle hThread);

AURA_API AuraThread_GetPriority(
        /* [in] */ Aura_Handle hThread,
        /* [out] */ Aura_ThreadPriority * pPriority);

AURA_API AuraThread_SetPriority(
        /* [in] */ Aura_Handle hThread,
        /* [in] */ Aura_ThreadPriority priority);

AURA_API AuraThread_GetProcessorTimes(
        /* [in] */ Aura_Handle hThread,
        /* [out] */ Aura_Millisecond32 * pUserTime,
        /* [out] */ Aura_Millisecond32 * pPrivilegedTime);

AURA_API_(Aura_Void) AuraThread_Quit(
        /* [in] */ Aura_QuitCode quitCode); // never returned;

AURA_API_(Aura_Void) AuraThread_Sleep(
        /* [in] */ Aura_Millisecond32 timeOut,
        /* [out] */ Aura_WaitResult * pResult);

AURA_API_(Aura_Void) AuraThread_Yield();

AURA_API_(Aura_Handle) AuraThread_GetCurrent();

AURA_API_(Aura_ThreadId) AuraThread_GetCurrentId();


// Interfaces for "module" of Aura.

AURA_API AuraModule_Load(
        /* [in] */ Aura_PWChar name,
        /* [in] */ Aura_ModuleLoadFlags flags,
        /* [out] */ Aura_Handle * phModule);

AURA_API AuraModule_Unload(
        /* [in] */ Aura_Handle hModule);

AURA_API AuraModule_GetInformation(
        /* [in] */ Aura_Handle hModule,
        /* [out] */ Aura_Address * pBaseAddr,
        /* [out] */ Aura_Address * pEntryAddr,
        /* [out] */ Aura_MemorySize * pSizeOfImage);

AURA_API AuraModule_GetProcAddressByName(
        /* [in] */ Aura_Handle hModule,
        /* [in] */ Aura_PChar name,
        /* [out] */ Aura_Address * pProcAddress);

AURA_API AuraModule_GetProcAddressByOrdinal(
        /* [in] */ Aura_Handle hModule,
        /* [in] */ Aura_Int32 ordinal,
        /* [out] */ Aura_Address * pProcAddress);

AURA_API AuraModule_GetFileName(
        /* [in] */ Aura_Handle hModule,
        /* [out] */ Aura_PWChar pFileName,
        /* [out] */ Aura_PWChar pPathName);

AURA_API AuraModule_GetResource(
        /* [in] */ Aura_Handle hModule,
        /* [in] */ Aura_PWChar resName,
        /* [in] */ Aura_PWChar resType,
        /* [out] */ Aura_Address * pAddress,
        /* [out] */ Aura_MemorySize * pSize);

// Interfaces for "Thread Local Storage" of Aura.

AURA_API AuraTls_Allocate(
        /* [out] */ Aura_UInt32 * pIndex);

AURA_API AuraTls_Free(
        /* [in] */ Aura_UInt32 uIndex);

AURA_API AuraTls_GetValue(
        /* [in] */ Aura_UInt32 uIndex,
        /* [out] */ Aura_PVoid * ppValue);

AURA_API AuraTls_SetValue(
        /* [in] */ Aura_UInt32 uIndex,
        /* [in] */ Aura_PVoid pValue);

// Interfaces for "Virtual Memory" of Aura.

AURA_API AuraVirtualMemory_Map(
        /* [in] */ Aura_Address vBaseAddr,
        /* [in] */ Aura_MemorySize size,
        /* [in] */ Aura_MemoryMapFlags flags,
        /* [in] */ Aura_MemoryProtection protect,
        /* [out] */ Aura_Address *pBaseAddr);

AURA_API AuraVirtualMemory_Query(
        /* [in] */ Aura_Address vAddress,
        /* [out] */ Aura_Address *pBaseAddr,
        /* [out] */ Aura_MemorySize *pSize);

AURA_API AuraVirtualMemory_SetProtection(
        /* [in] */ Aura_Address vBaseAddr,
        /* [in] */ Aura_MemorySize size,
        /* [in] */ Aura_MemoryProtection protect);

AURA_API AuraVirtualMemory_CheckProtection(
        /* [in] */ Aura_Address vAddress,
        /* [in] */ Aura_MemoryProtection protect,
        /* [out] */ Aura_Bool *pIsValid);

AURA_API AuraVirtualMemory_Commit(
        /* [in] */ Aura_Address vAddress);

AURA_API AuraVirtualMemory_IORemap(
        /* [in] */ Aura_Address virtualAddr,
        /* [in] */ Aura_MemorySize size,
        /* [in] */ Aura_Address physicalAddr,
        /* [in] */ Aura_MemoryMapFlags flags,
        /* [in] */ Aura_MemoryProtection protect,
        /* [out] */ Aura_Address *pVirtualAddr);

AURA_API AuraVirtualMemory_Unmap(
        /* [in] */ Aura_Address vBaseAddr,
        /* [in] */ Aura_MemorySize size);

// Interfaces for "Mutex" of Aura.

AURA_API AuraMutex_Create(
        /* [out] */ Aura_Handle * phMutex);

AURA_API AuraMutex_Lock(
        /* [in] */ Aura_Handle hMutex,
        /* [in] */ Aura_Millisecond32 timeOut,
        /* [out] */ Aura_WaitResult * pResult);

AURA_API AuraMutex_Unlock(
        /* [in] */ Aura_Handle hMutex);

AURA_API AuraMutex_Destroy(
        /* [in] */ Aura_Handle hMutex);

// Interfaces for "Event " of Aura.

AURA_API AuraEvent_Create(
        /* [in] */ Aura_Bool bManualReset,
        /* [in] */ Aura_EventState initialState,
        /* [out] */ Aura_Handle  * phEvent);

AURA_API AuraEvent_Wait(
        /* [in] */ Aura_Handle hEvent,
        /* [in] */ Aura_Millisecond32 timeOut,
        /* [out] */ Aura_WaitResult * pResult,
        /* [out] */ Aura_EventState * pReserved);

AURA_API AuraEvent_Signal(
        /* [in] */ Aura_Handle hEvent,
        /* [in] */ Aura_EventState reserved);

AURA_API AuraEvent_Unsignal(
        /* [in] */ Aura_Handle hEvent);

AURA_API AuraEvent_Destroy(
        /* [in] */ Aura_Handle hEvent);

// Interfaces for "Condition " of Aura.

AURA_API AuraCondition_Create(
        /* [in] */ Aura_Handle * phCondition);

AURA_API AuraCondition_Wait(
        /* [in] */ Aura_Handle hCondition,
        /* [in] */ Aura_Handle hMutex,
        /* [in] */ Aura_Millisecond32 timeOut,
        /* [out] */ Aura_WaitResult * pResult);

AURA_API AuraCondition_Pulse(
        /* [in] */ Aura_Handle hCondition);

AURA_API AuraCondition_PulseAll(
        /* [in] */ Aura_Handle hCondition);

AURA_API AuraCondition_Destroy(
        /* [in] */ Aura_Handle hCondition);

// Interfaces for "Shared Memory" of Aura.

AURA_API AuraSharedMemory_Create(
        /* [in] */ Aura_PWChar name,
        /* [in] */ Aura_MemorySize size,
        /* [in] */ Aura_Bool bCommit,
        /* [out] */ Aura_Handle * phSharedMemory,
        /* [out] */ Aura_Bool * pbAlreadyExisted);

AURA_API AuraSharedMemory_Attach(
        /* [in] */ Aura_Handle hSharedMemory,
        /* [in] */ Aura_MemoryProtection protect,
        /* [out] */ Aura_Address * pAddress);

AURA_API AuraSharedMemory_Detach(
        /* [in] */ Aura_Handle hSharedMemory,
        /* [in] */ Aura_Address Aura_Address);

AURA_API AuraSharedMemory_Destroy(
        /* [in] */ Aura_Handle hSharedMemory);

// Interfaces for "Critical Section" of Aura.

AURA_API AuraCriticalSection_Create(
        /* [out] */ Aura_Handle * phCriticalSection);

AURA_API AuraCriticalSection_Enter(
        /* [in] */ Aura_Handle hCriticalSection);

AURA_API AuraCriticalSection_Leave(
        /* [in] */ Aura_Handle hCriticalSection);

AURA_API AuraCriticalSection_Destroy(
        /* [in] */ Aura_Handle hCriticalSection);

// " CRT" category interface functions.

EXTERN_C Aura_PVoid __cdecl
Aura_malloc(
      /* [in]  */ Aura_Int32 size);

EXTERN_C Aura_PVoid __cdecl
Aura_realloc(
      /* [in]  */ Aura_PVoid p,
      /* [in]  */ Aura_Int32 size);

EXTERN_C Aura_Void __cdecl
Aura_free(
      /* [in]  */ Aura_PVoid p);

EXTERN_C Aura_Int32 __cdecl
Aura_putws(
      /* [in]  */ const Aura_PWChar wstr);

EXTERN_C Aura_Int32 __cdecl
Aura_printf(
      /* [in]  */ const Aura_PChar fmt, ...);

#endif //__AURA_INTERFACE_H__

